/*
 * @Date         : 2022-02-28 10:47:15
 * @LastEditors  : zu1662
 * @LastEditTime : 2022-02-28 10:59:17
 * @Description  : Mock的一些工具函数
 * 
 * Copyright © 2022 by zu1662, All Rights Reserved. 
 */

// 获取 query params 封装
export function getQueryParams(opts: { url: string}) {
  const url = opts.url
  const search = url.split('?')[1]
  if (!search) {
    return {}
  }
  return JSON.parse('{"' + decodeURIComponent(search)
    .replace(/"/g, '\\"')
    .replace(/&/g, '","')
    .replace(/=/g, '":"') + '"}')
}

// 获取 post body 入参封装
export function getBody(opts: {body: any}) {
  return opts.body && JSON.parse(opts.body)
}